package com.gzdh.tang.modu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gzdh.tang.modu.entity.TangOrder;
import com.gzdh.tang.modu.model.DeviceCarModel;
import com.gzdh.tang.modu.model.ReportModel;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface TangOrderMapper extends BaseMapper<TangOrder> {

    @Select("select RIGHT(1000000+(ISNULL(MAX(code),0)+1),4) as dh from tang_liushui " +
            "where order_time=#{order_time} ")
    String getDhLiuShui(@Param("order_time") String orderTime);

    @Insert("insert into tang_liushui values(#{addr},#{code},#{order_time})")
    int insertDhLiuShui(@Param("addr") int addr, @Param("order_time") String orderTime, @Param("code") String code);


    DeviceCarModel queryDeviceCar(@Param("orders") String orders);

    List<DeviceCarModel> queryDeviceCarForList(@Param("orders") String orders);

    @Update("update tang_order set pay_channel=#{payChannel} where id=#{id}")
    int updateTangOrderPayChannel(@Param("payChannel") int payChannel, @Param("id") String id);


    @Update("update tang_order set pay_channel=#{payChannel} where orders=#{orders}")
    int updateTangOrderPayChannelByOrders(@Param("payChannel") int payChannel, @Param("orders") String orders);


    @Update("update tang_order set pay_state=#{payState} where orders=#{orders}")
    int updateTangOrderPayStateByOrders(@Param("payState") int payState, @Param("orders") String orders);


    @Select("select pay_channel,addr,SUM(amount_count) as amount_count,SUM(amount_price) as amount_price from tang_order " +
            "where pay_state=1 and addr=#{addr} and create_time>=#{startTime} and create_time<=#{endTime} " +
            "group by pay_channel,addr")
    List<ReportModel> getReport(@Param("addr") int addr, @Param("startTime") String startTime, @Param("endTime") String endTime);

    //    @Select(" select sc as pay_channel,addr,SUM(sl) as amount_count ,SUM(JE) as amount_price  from RESERVE  " +
//            " where addr=#{addr}  and CZRQ>=#{startTime} and CZRQ<=#{endTime}   and cs=0 " +
//            " group by sc,addr")
    List<ReportModel> getReport2(@Param("addr") int addr, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("posnum") String posnum);

    @Update("update tang_order set pay_state=#{payState} where id=#{id}")
    int updateOrderPayState(@Param("id") String id, @Param("payState") int payState);


    @Update("update tang_order set notice_reserve=1 where id=#{id}")
    int updateOrderNoticeReserve(@Param("id") String id);
}
